using System;
using System.Collections.Generic;
using System.Text;
using SharpMud.MudLib.Common.Resourcing;
using SharpMud.Server.Systems;
using System.IO;
using SharpMud.MudLib.Common.Entities.Players.Session;
using SharpMud.MudLib.Common.Entities.Players.Session.States;
using SharpMud.Net;

namespace SharpMud.MudLib.Common.Entities.Players
{
    public interface IPlayerManager : IGuidIdentifiedResourceHost, IUriIdentifiedResourceHost, IServerSystem
    {
        /// <summary>
        /// Gets the player manager to determine if the player with the given name actually
        /// exists or not
        /// </summary>
        bool PlayerExists(string playerName);

        /// <summary>
        /// Gets the player manager to determine if the given player name is valid, whether or
        /// not the player already exists
        /// </summary>
        bool IsValidPlayerName(string potentialPlayerName);

        /// <summary>
        /// Determines if the player with the given name is actually currently loaded into
        /// memory, regardless if the player is loaded for playing or not
        /// </summary>
        bool IsPlayerLoaded(string playerName);

        /// <summary>
        /// Determines if the player with the given name is loaded and playing
        /// </summary>
        bool IsPlayerPlaying(string playerName);

        /// <summary>
        /// Determines if the given player is currently playing the game
        /// </summary>
        bool IsPlayerPlaying(IPlayerCharacter playerCharacter);

        /// <summary>
        /// Gets the player with the given name, and will load the character if neccesary
        /// </summary>
        /// <returns>Returns the IPlayerCharacter if the player is found, otherwise Null</returns>
        IPlayerCharacter GetPlayer(string playerName);

        /// <summary>
        /// Gets the player with the given name, but only loads an unloaded player if 'loadIfNeccesary' is set to true
        /// </summary>
        /// <returns>Returns the IPlayerCharacter if found, if it is not found or not loaded, Null is returned</returns>
        IPlayerCharacter GetPlayer(string playerName, bool loadIfNeccesary);

        /// <summary>
        /// Gets the System.IO.FileInfo for the player file for the player with the given name
        /// </summary>
        /// <remarks>Even if the player file does not exist, a FileInfo initialized with a hypothetical
        /// filename will be provided.</remarks>
        FileInfo GetPlayerFileInfo(string playerName);

        /// <summary>
        /// Retrieves the IBaseMudLibRoot that is the core of this MudLib server application
        /// </summary>
        new IBaseMudLibRoot Host { get;}

        /// <summary>
        /// Saves the given player character to disk
        /// </summary>
        /// <param name="player">The player character to save to disk</param>
        /// <exception cref="InvalidCastException">Thrown when the given IPlayerCharacter is not supported by this IPlayerManager</exception>
        void SavePlayer(IPlayerCharacter player);

        ISessionState<TelnetPlayerSession> GetStartingTelnetSessionState(INetworkConnection connection);
    }
}